<?php

class adminNew{
	public $action;
	public $id;
	public $name;
	public $hot;
	

	function __construct($action='',$id='',$name='',$hot=''){
		$this->action=$action;
		$this->id=$id;
		$this->name=$name;
		$this->hot=$hot;
	}

	function getAction(){
		switch($this->action) {
			case add_city:$this->add_city(); break;
			case add_school:$this->add_school(); break;

			case update:; break;
			case del:; break;
		}
	}

	function query(){
		return $mysql=mysql_query("select * from city");
	}

	function get($mysql){
		$info=mysql_fetch_array($mysql);
		return $info;
	}

	function add_city(){
		$query=mysql_query("select * from school where sname='$name'");
		$city=mysql_fetch_array($query);
		if($city==false){
		     $add=mysql_query("insert into city(cname) values ('$this->name')");
             echo "<script language='javascript'>alert('添加成功!');history.back();</script>";
		}else{
            echo "<script language='javascript'>alert('此城市已经存在!');history.back();</script>";
		}

	}

	function add_school($cid,$name,$hot){
		$query=mysql_query("select * from school where sname='$name'");
		$school=mysql_fetch_array($query);
		if($school==false){
		     $add=mysql_query("insert into school(city_id,sname,is_hot) values ('$cid','$name','$hot')");
             echo "<script language='javascript'>alert('添加成功!');history.back();</script>";
		}else{
            echo "<script language='javascript'>alert('此学校已经存在!');history.back();</script>";
		}

	}



}